﻿// TestSharedData.UserIdentity.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       UserIdentity.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace TestSharedData
{
	#region Using Directives
	using System;
	using System.Security.Principal;
	using System.Web.Security;
	#endregion

	#region UserIdentity
	/// <summary>
	/// An entity class that represents a User and implements <see cref="IIdentity"/>.
	/// </summary>
	public partial class UserIdentity : IIdentity
	{
		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		public UserIdentity() { }
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="ticket">The FormsAuthenticationTicket that represents an authenticated user</param>
		/// <param name="isAuthenticated">A flag indicating if this instance represents an Authenticated User</param>
		internal UserIdentity(FormsAuthenticationTicket ticket, bool isAuthenticated)
		{
			this.Name = ticket.Name;

			this.CompanyId = Guid.NewGuid();
			this.CompanyName = "HighSpeed-Solutions";
			this.IsCompanyActive = true;
			this.UserId = Guid.NewGuid();
			this.UserName = this.Name;
			this.FirstName = "Test User";
			this.LastName = "TESTER";
			this.DisplayName = "tester";
			this.Email = "sales@highspeed-solutions.net";
			this.IsCreated = true;

			this.IsAuthenticated = isAuthenticated;
		}
		#endregion

		#region Properties

		/// <summary>
		/// Gets if this Identity has been successful created 
		/// and represents an actual User, but does not
		/// indicate if they've been authenticated
		/// </summary>
		public bool IsCreated
		{
			get;
			private set;
		}
		/// <summary>
		/// Gets the Authentication type
		/// </summary>
		public string AuthenticationType
		{
			get { return "custom"; }
		}
		/// <summary>
		/// Gets a flag indicating if the user is Authenticated
		/// </summary>
		public bool IsAuthenticated
		{
			get;
			internal set;
		}
		/// <summary>
		/// Gets the Authenticated UserName
		/// </summary>
		public string Name
		{
			get;
			internal set;
		}

		/// <summary>
		/// Gets or sets the Id of the Users Company
		/// </summary>
		public Guid CompanyId
		{
			get { return _companyId; }
			set
			{
				_companyId = value;
			}
		} Guid _companyId;
		/// <summary>
		/// Gets or sets the Users CompanyName
		/// </summary>
		public string CompanyName
		{
			get { return _companyName; }
			set
			{
				_companyName = value;
			}
		} string _companyName;
		/// <summary>
		/// Gets or sets if the Users Company is active
		/// </summary>
		public bool IsCompanyActive
		{
			get { return _isCompanyActive; }
			set
			{
				_isCompanyActive = value;
			}
		} bool _isCompanyActive;
		/// <summary>
		/// Gets or sets the Users Id
		/// </summary>
		public Guid UserId
		{
			get { return _userId; }
			set
			{
				_userId = value;
			}
		} Guid _userId;
		/// <summary>
		/// Gets or sets the User Name
		/// </summary>
		public string UserName
		{
			get { return _userName; }
			set
			{
				_userName = value;
			}
		} string _userName;
		/// <summary>
		/// Gets or sets the Users FirstName
		/// </summary>
		public string FirstName
		{
			get { return _firstName; }
			set
			{
				_firstName = value;
			}
		} string _firstName;
		/// <summary>
		/// Gets or sets the Users LastName
		/// </summary>
		public string LastName
		{
			get { return _lastName; }
			set
			{
				_lastName = value;
			}
		} string _lastName;
		/// <summary>
		/// Gets or sets the Users Display Name
		/// </summary>
		public string DisplayName
		{
			get { return _displayName; }
			set
			{
				_displayName = value;
			}
		} string _displayName;
		/// <summary>
		/// Gets or sets the Users DefaultHomePage
		/// </summary>
		public string DefaultHomePage
		{
			get { return _defaultHomePage; }
			set
			{
				if (_defaultHomePage != value)
				{
					_defaultHomePage = value;
				}
			}
		} string _defaultHomePage;
		/// <summary>
		/// Gets or sets the User's Email Address
		/// </summary>
		public string Email
		{
			get { return _email; }
			set
			{
				_email = value;
			}
		} string _email;
		/// <summary>
		/// Gets or sets whether or not the user is approved.
		/// </summary>
		public bool IsApproved
		{
			get { return _isApproved; }
			set
			{
				_isApproved = value;
			}
		} bool _isApproved;
		/// <summary>
		/// Gets or sets whether or not the user is currently locked out of the system
		/// </summary>
		public bool IsLockedOut
		{
			get { return _isLockedOut; }
			set
			{
				_isLockedOut = value;
			}
		} bool _isLockedOut;
		/// <summary>
		/// Gets or sets whether or not this if the first time the user is logging into the system
		/// </summary>
		public bool FirstLogin
		{
			get { return _firstLogin; }
			set
			{
				_firstLogin = value;
			}
		} bool _firstLogin;
		/// <summary>
		/// Gets or sets whether or not the user needs to reset their password
		/// </summary>
		public bool NeedPasswordReset
		{
			get { return _needPasswordReset; }
			set
			{
				_needPasswordReset = value;
			}
		} bool _needPasswordReset;
		/// <summary>
		/// Gets the number of days before the user's password is going to expire.
		/// </summary>
		public int PasswordAboutToExpire { get; set; }
		/// <summary>
		/// Gets or sets if the users password never expires.
		/// </summary>
		public bool PasswordNeverExpires
		{
			get { return _passwordNeverExpires; }
			set
			{
				_passwordNeverExpires = value;
			}
		} bool _passwordNeverExpires;
		/// <summary>
		/// Gets or sets the Password Question for the user
		/// </summary>
		public string PasswordQuestion
		{
			get { return _passwordQuestion; }
			set
			{
				_passwordQuestion = value;
			}
		} string _passwordQuestion;
		/// <summary>
		/// Gets or sets the user's Last Activity Date
		/// </summary>
		public DateTime LastActivityDate
		{
			get { return _lastActivityDate; }
			set
			{
				_lastActivityDate = value;
			}
		} DateTime _lastActivityDate;
		/// <summary>
		/// Gets the user's Last Activity Date in Local Time.
		/// </summary>
		public DateTime LastActivityDateLocalTime
		{
			get
			{
				if (null == LastActivityDate)
					return DateTime.MinValue;
				else
					return LastActivityDate.ToLocalTime();
			}
		}
		/// <summary>
		/// Gets or sets the date and time the user's password was last changed
		/// </summary>
		public DateTime LastPasswordChangedDate
		{
			get { return _lastPasswordChangedDate; }
			internal set
			{
				_lastPasswordChangedDate = value;
			}
		} DateTime _lastPasswordChangedDate;
		/// <summary>
		/// Gets the date and time the user's password was last changed in Local Time.
		/// </summary>
		public DateTime LastPasswordChangedDateLocalTime
		{
			get
			{
				if (null == LastPasswordChangedDate)
					return DateTime.MinValue;
				else
					return LastPasswordChangedDate.ToLocalTime();
			}
		}
		/// <summary>
		/// Gets or sets the User's last login date
		/// </summary>
		public DateTime LastLoginDate
		{
			get { return _lastLoginDate; }
			set
			{
				_lastLoginDate = value;
			}
		} DateTime _lastLoginDate;
		/// <summary>
		/// Gets or sets the User's last login date in local time.
		/// </summary>
		public DateTime LastLoginDateLocalTime
		{
			get
			{
				if (null == LastLoginDate)
					return DateTime.MinValue;
				else
					return LastLoginDate.ToLocalTime();
			}
		}
		/// <summary>
		/// Gets or sets the User's last lockout date
		/// </summary>
		public DateTime LastLockoutDate
		{
			get { return _lastLockoutDate; }
			set
			{
				_lastLockoutDate = value;
			}
		} DateTime _lastLockoutDate;
		/// <summary>
		///Gets the User's last lockout date in local time.
		/// </summary>
		public DateTime LastLockoutDateLocalTime
		{
			get
			{
				if (null == LastLockoutDate)
					return DateTime.MinValue;
				else
					return LastLockoutDate.ToLocalTime();
			}
		}
		/// <summary>
		/// Gets or sets whether or not this user is a System Account
		/// </summary>
		public bool IsSystemAccount
		{
			get { return _isSystemAccount; }
			set
			{
				_isSystemAccount = value;
			}
		} bool _isSystemAccount;
		/// <summary>
		/// Gets or sets the Comments for the user
		/// </summary>
		public string Comment
		{
			get { return _comment; }
			set
			{
				_comment = value;
			}
		} string _comment;
		/// <summary>
		/// Gets or sets the Created Date
		/// </summary>
		public DateTime CreatedDate
		{
			get { return _createdDate; }
			set
			{
				_createdDate = value;
			}
		} DateTime _createdDate;
		/// <summary>
		/// Gets or sets the last Update Date
		/// </summary>
		public DateTime UpdatedDate
		{
			get { return _updatedDate; }
			set
			{
				_updatedDate = value;
			}
		} DateTime _updatedDate;
		/// <summary>
		/// Gets or sets who performed the last Update
		/// </summary>
		public string UpdatedBy
		{
			get { return _updatedBy; }
			set
			{
				_updatedBy = value;
			}
		} string _updatedBy;
		#endregion

		#region Static
		/// <summary>
		/// The name of an Anonymous User (Guest)
		/// </summary>
		public static string AnonymousUserName
		{
			get { return "Guest"; }
		}
		#endregion
	}
	#endregion
}